package com.woniuxy.stage3demo.service.servicehpd.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.hpd.ProductBean;
import com.woniuxy.stage3demo.bean.hpd.ProductLogBean;
import com.woniuxy.stage3demo.mapper.mapperhpd.ProductLogMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.servicehpd.IProductLogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true)
@Service
public class ProductLogServiceImpl implements IProductLogService {
    @Resource
    private ProductLogMapper productLogMapper;


    @Override
    public PageInfo<ProductLogBean> findAll(PageRequest request) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->productLogMapper.findAll(request));
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int addProductLog(ProductBean oldProductBean, ProductBean newProductBean) {
        return productLogMapper.addProductLog(oldProductBean,newProductBean);
    }

   @Override
    public List<ProductLogBean> findByProductId(Long productId) {
        return productLogMapper.findByProductId(productId);
    }
}
